﻿
using GalFrameWork.Models;
using SQLite;


namespace GalFrameWork.Service.Impl; 

public class ProcessStorage : IProcessStorage
{


    public const string DbFileName = "Dialogdb.sqlite3";


    public static readonly string PoetryDbPath =
        Path.Combine(
            Environment.GetFolderPath(Environment.SpecialFolder
                .LocalApplicationData), DbFileName);

    private SQLiteAsyncConnection _connection;



    public SQLiteAsyncConnection Connection =>
        _connection ??= new SQLiteAsyncConnection(PoetryDbPath);



    public async Task Initialize() {
        await Connection.CreateTableAsync<Process>();
    }

    public async Task Add(Process process) {
        await Connection.InsertAsync(process);
    }

    public async Task<IEnumerable<Process>> List()
    {
        return await Connection.Table<Process>().ToListAsync();
    }
}